//
//  SNEquipmentViewController.m
//  project
//
//  Created by 黄建华 on 2017/11/20.
//  Copyright © 2017年 黄建华. All rights reserved.
//

#import "SNEquipmentViewController.h"
#import "CameraViewController.h"
#import "FindBlueViewController.h"
#import "DeviceSetViewController.h"
#import "HealthSetViewController.h"
#import "ScheduleViewController.h"
#import "AlarmViewController.h"
#import "MessagePushViewController2.h"
#import "MessagePushViewController.h"
#import "FindBandView.h"
#import "SNEquipmentScreenViewController.h"
@interface SNEquipmentViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UILabel     *titleLabel;
@property (nonatomic, strong) UIImageView *powerImage;
@property (nonatomic, strong) UIImageView *showPower;
@property (nonatomic, strong) UILabel     *macLabel;
@property (nonatomic, strong) UIImageView *animateView;
@property (nonatomic, strong) UIView      *bgView;
@property (nonatomic, strong) UILabel     *powerLabel;
@property (nonatomic, strong) UIButton    *setBtn;
@property (nonatomic, strong) UIImageView *backImageView;

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray     *dataArray;
@property (nonatomic, strong) NSArray     *imageArray;
@property (nonatomic, strong) NSArray    *array1;
@property (nonatomic, strong) NSArray    *array2;
@property (nonatomic, strong) NSArray    *array3;

@end

@implementation SNEquipmentViewController

- (void)OTACANINFONOTICE2 {
    NSLog(@"🙂3333 otaUpdateInfoView");
    [self otaUpdateInfoView];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    CustomTabBar *tabBar = (CustomTabBar *)self.tabBarController;
    [tabBar showTheTabBarView];
    
    if ([FileModelEntity sharedInstance].otacanInfo) {
        NSLog(@"🙂直接弹OTA 11111");
        [self otaUpdateInfoView];
    } else {
        NSLog(@"🙂等待直接弹OTA 22222");
    }

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(OTACANINFONOTICE2) name:OTACANINFONOTICE object:nil];

    //    [[UIView appearance] setTintColor:[UIColor clearColor]];
    if ([APPFIRST getBOOLValue]) {
        if (!KK_BLEConnect.centerPowerOn) {
            SHOWMBProgressHUD(nil, SN_Text(@"检测到你的手机蓝牙功能未启用，请前往手机的[设置]启用蓝牙功能"), nil, NO, 0.5);
        }
        [APPFIRST setBOOLValue:NO];
    }

    [KK_BLESend sendGetDeviceBasicInfoWithUpdate:^(id object, KKBLEAcceptType type) {
     }];

    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(delayGetNotice) object:nil];
    [self performSelector:@selector(delayGetNotice) withObject:nil afterDelay:1.0];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }

//    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(refreshCurrentView) object:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    UIView *StateView = [[UIView alloc] init];
    StateView.frame           = CGRectMake(0, 0, kSCREEN_WIDTH, 20);
    StateView.backgroundColor = BBIGSTATECOLOR;
    [self.view addSubview:StateView];

    UIView *naView = [[UIView alloc] init];
    naView.frame           = CGRectMake(0, 20+FitSimpleIpx(0, 20), kSCREEN_WIDTH, 44);
    naView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:naView];

    _setBtn       = [UIButton buttonWithType:UIButtonTypeCustom];
    _setBtn.frame = CGRectMake(HHHWIDTH-44-10, 0, 44, 44);
    [_setBtn setImageNormal:@"设置2"];
    [_setBtn addTouchUpTarget:self action:@selector(pushToSetVC:)];
    [naView addSubview:_setBtn];

    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 20+FitSimpleIpx(0, 20), screenWidth, 44)];
    lable.textColor     = UIColorHEX(0x161616);
    lable.font          = SNFONTMEDIUM(16);
    lable.textAlignment = NSTextAlignmentCenter;
    lable.text          = HHH_Text(@"设备");

    [self.view addSubview:lable];

//    SNShadowView *shadowLine = [[SNShadowView alloc] init];
//    shadowLine.frame = SNFRAME(0, 20+FitSimpleIpx(0, 20) + 44, HHHWIDTH, 0);
//    [shadowLine showWithType:1];
//    [self.view addSubview:shadowLine];
    
//    UIImageView *shadowLine = [[UIImageView alloc] init];
//    shadowLine.frame = SNFRAME(0, 20+FitSimpleIpx(0, 20) + 44 -2, HHHWIDTH, 2);
//    shadowLine.image = [UIImage image:@"lineImage"];
//    [self.view addSubview:shadowLine];

    [self.view addSubview:self.tableView];
    self.tableView.frame = SNFRAME(0, FitSimpleIpx(64, 88), screenWidth, screenHeight - FitSimpleIpx(64, 88) -60);

    [KK_BLESend sendGetDeviceBasicInfoWithUpdate:^(id object, KKBLEAcceptType type) {
     }];

    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(delayGetNotice) object:nil];
    [self performSelector:@selector(delayGetNotice) withObject:nil afterDelay:1.0];



    if (SN_USER.wallpaper) {
    }


    [self updateArrayWith];
}

- (void)updateArrayWith
{
    _dataArray = @[SN_Text(@"设备"), SN_Text(@"当前电量"), HHH_Text(@"远程相机"), HHH_Text(@"查找手环"), HHH_Text(@"健康提醒"), HHH_Text(@"日程管理"), HHH_Text(@"闹钟"), HHH_Text(@"推送")];
    _imageArray = @[@"手环设备", @"电量", @"相机(1)", @"搜索", @"健康", @"日程(1)", @"闹钟(1)", @"推送"];
    
    _array1 = @[SN_Text(@"设备"),SN_Text(@"当前电量")];
    _array2 = @[SN_Text(@"远程相机"),SN_Text(@"查找手环"),HHH_Text(@"健康提醒"),HHH_Text(@"日程管理"), HHH_Text(@"闹钟")];
    _array3 = @[HHH_Text(@"推送")];
    [self.tableView reloadData];
}

- (void)addHeadeView {
    UIImage *backImage = UIImageNamed(@"背景");

    _backImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 20+FitSimpleIpx(0, 20), HHHWIDTH, HHHWIDTH*backImage.size.height/backImage.size.width)];

    _backImageView.userInteractionEnabled = YES;
    _backImageView.image                  = backImage;
    [self.view addSubview:_backImageView];

    _titleLabel               = [[UILabel alloc]initWithFrame:CGRectMake(0, 20+FitSimpleIpx(0, 20), HHHWIDTH, 44)];
    _titleLabel.text          = @"";
    _titleLabel.font          = SNFONT(18.);
    _titleLabel.textColor     = [UIColor whiteColor];
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_titleLabel];

    _setBtn       = [UIButton buttonWithType:UIButtonTypeCustom];
    _setBtn.frame = CGRectMake(HHHWIDTH-44-10, 20+FitSimpleIpx(0, 20)+5, 44, 44);
    if (KK_BLEConnect.model.isConnected) {
        [_setBtn setImageNormal:@"设置2"];
    }
    [_setBtn addTouchUpTarget:self action:@selector(pushToSetVC:)];
    [self.view addSubview:_setBtn];

    _powerLabel               = [[UILabel alloc]initWithFrame:CGRectMake(FitW(20), _backImageView.height*0.332, HHHWIDTH-FitW(20), FitH(25))];
    _powerLabel.textAlignment = NSTextAlignmentLeft;
    _powerLabel.font          = SNFONTMIN(15);
    _powerLabel.text          = SN_Text(@"当前电量");
    _powerLabel.textColor     = [UIColor whiteColor];
    CGSize titleSize = [_powerLabel.text sizeWithFont:_powerLabel.font maxSize:CGSizeMake(MAXFLOAT, FitH(25))];
    _powerLabel.size = titleSize;
    [self.view addSubview:_powerLabel];

    _powerImage       = [[UIImageView alloc]initWithFrame:CGRectMake(_powerLabel.right +3, _powerLabel.centerY - 30/2, 40, 30)];
    _powerImage.image = [UIImage imageNamed:@"icon_electricity_lv1"];
    [self.view addSubview:_powerImage];

    _showPower                 = [[UIImageView alloc] initWithFrame:CGRectMake(5, 10, _powerImage.width-11, _powerImage.height-20)];
    _showPower.backgroundColor = [UIColor whiteColor];

    [_powerImage addSubview:_showPower];

    _macLabel               = [[UILabel alloc]initWithFrame:CGRectMake(FitW(20), _powerImage.origin.y +35, HHHWIDTH-FitW(20), FitH(20))];
    _macLabel.textAlignment = NSTextAlignmentLeft;
    _macLabel.font          = SNFONTMIN(15);
    _macLabel.textColor     = [UIColor whiteColor];
    [self.view addSubview:_macLabel];
}

- (void)btnClick:(UIButton *)sender {
    sender.enabled = NO;
    // 99999999
    if (SN_USER.wallpaper) {
        if (sender.tag == 100 || sender.tag == 102) {
            // 空余的按钮
        } else if (sender.tag == 101) {
            SNEquipmentScreenViewController *vc     = [[SNEquipmentScreenViewController alloc]init];
            CustomTabBar                    *tabBar = (CustomTabBar *)self.tabBarController;
            [tabBar hiddenTheTabBarView];
            [self.navigationController pushViewController:vc animated:YES];
        } else if (sender.tag == 103) {
            CameraViewController *cameraVC = [[CameraViewController alloc]init];
            [self.navigationController pushViewController:cameraVC animated:YES];
        } else if (sender.tag == 104) {
            FindBandView *findBandView = [[FindBandView alloc]initWithFrame:CGRectMake(0, 0, HHHWIDTH, HHHHEIGHT)];
            [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:findBandView];
            [findBandView animationUp];
            [KK_BLESend sendSetFindBle:YES withUpdateBlock:^(id object, KKBLEAcceptType type)
             {
             }];
        } else if (sender.tag == 105) {
            HealthSetViewController *healthVC = [[HealthSetViewController alloc]init];
            CustomTabBar            *tabBar   = (CustomTabBar *)self.tabBarController;
            [tabBar hiddenTheTabBarView];
            [self.navigationController pushViewController:healthVC animated:YES];
        } else if (sender.tag == 106) {
            ScheduleViewController *scheduleVC = [[ScheduleViewController alloc]init];
            CustomTabBar           *tabBar     = (CustomTabBar *)self.tabBarController;
            [tabBar hiddenTheTabBarView];
            [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
            [self.navigationController pushViewController:scheduleVC animated:YES];
        } else if (sender.tag == 107) {
            AlarmViewController *alarmVC = [[AlarmViewController alloc]init];
            CustomTabBar        *tabBar  = (CustomTabBar *)self.tabBarController;
            [tabBar hiddenTheTabBarView];
            [self.navigationController pushViewController:alarmVC animated:YES];
        } else if (sender.tag == 108) {
            if (SN_USER.isNewAncs) {
                MessagePushViewController2 *pushVC = [[MessagePushViewController2 alloc]init];
                CustomTabBar               *tabBar = (CustomTabBar *)self.tabBarController;
                [tabBar hiddenTheTabBarView];
                [self.navigationController pushViewController:pushVC animated:YES];
            } else {
                MessagePushViewController *pushVC = [[MessagePushViewController alloc]init];
                CustomTabBar              *tabBar = (CustomTabBar *)self.tabBarController;
                [tabBar hiddenTheTabBarView];
                [self.navigationController pushViewController:pushVC animated:YES];
            }
        }
    } else {
        if (sender.tag == 100) {
            CameraViewController *cameraVC = [[CameraViewController alloc]init];
            CustomTabBar         *tabBar   = (CustomTabBar *)self.tabBarController;
            [tabBar hiddenTheTabBarView];
            [self.navigationController pushViewController:cameraVC animated:YES];
        } else if (sender.tag == 101) {
            FindBandView *findBandView = [[FindBandView alloc]initWithFrame:CGRectMake(0, 0, HHHWIDTH, HHHHEIGHT)];
            [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:findBandView];
            [findBandView animationUp];
            [KK_BLESend sendSetFindBle:YES withUpdateBlock:^(id object, KKBLEAcceptType type)
             {
             }];
        } else if (sender.tag == 102) {
            HealthSetViewController *healthVC = [[HealthSetViewController alloc]init];
            CustomTabBar            *tabBar   = (CustomTabBar *)self.tabBarController;
            [tabBar hiddenTheTabBarView];
            [self.navigationController pushViewController:healthVC animated:YES];
        } else if (sender.tag == 103) {
            ScheduleViewController *scheduleVC = [[ScheduleViewController alloc]init];
            CustomTabBar           *tabBar     = (CustomTabBar *)self.tabBarController;
            [tabBar hiddenTheTabBarView];
            [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
            [self.navigationController pushViewController:scheduleVC animated:YES];
        } else if (sender.tag == 104) {
            AlarmViewController *alarmVC = [[AlarmViewController alloc]init];
            CustomTabBar        *tabBar  = (CustomTabBar *)self.tabBarController;
            [tabBar hiddenTheTabBarView];
            [self.navigationController pushViewController:alarmVC animated:YES];
        } else if (sender.tag == 105) {
            if (SN_USER.isNewAncs) {
                MessagePushViewController2 *pushVC = [[MessagePushViewController2 alloc]init];
                CustomTabBar               *tabBar = (CustomTabBar *)self.tabBarController;
                [tabBar hiddenTheTabBarView];
                [self.navigationController pushViewController:pushVC animated:YES];
            } else {
                MessagePushViewController *pushVC = [[MessagePushViewController alloc]init];
                CustomTabBar              *tabBar = (CustomTabBar *)self.tabBarController;
                [tabBar hiddenTheTabBarView];
                [self.navigationController pushViewController:pushVC animated:YES];
            }
        }
    }
    sender.enabled = YES;
}

- (void)pushToSetVC:(UIButton *)sender {
//    if (!KK_BLEConnect.isConnected) {
//        SHOWMBProgressHUD(SN_Text(@"设备未连接"), nil, nil, NO, 2.0);
//        return;
//    }
    
    sender.enabled = NO;
    DeviceSetViewController *deviceVC = [[DeviceSetViewController alloc]init];
    CustomTabBar            *tabBar   = (CustomTabBar *)self.tabBarController;
    [tabBar hiddenTheTabBarView];
    [self.navigationController pushViewController:deviceVC animated:YES];
    sender.enabled = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

    [[NSNotificationCenter defaultCenter]removeObserver:self name:OTACANINFONOTICE object:nil];

    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(delayGetNotice) object:nil];
}

- (void)delayGetNotice {
    [KK_BLESend sendGet529WithBlock:^(id object, KKBLEAcceptType type) {
     }];
}

- (void)updateModel:(KKBLEModel *)model type:(KKBLEUpdateType)type {
     NSLog(@"🙂设备updateModel:(KKBLEModel *)model type:(KKBLEUpdateType)type");
    
    if (type == KKBLEUpdateDidConnect) {
        NSLog(@"🙂设备连接>>>>>>");
    }
    
    if (type == KKBLEUpdateDisConnect) {
        NSLog(@"🙂设备断开>>>>>>");
    }
    
    if (type == KKBLEUpdatePowerOn) {
        SHOWMBProgressHUD(SN_Text(@"蓝牙开启..."), nil, nil, NO, 2.0);
    }
    
    
    
    [self.tableView reloadData];
}

// 通知界面接收数据刷新相应界面的UI UpdateUiType
- (void)updateView:(KKBLEAcceptType)type {
    if (type == KKBLEAcceptTypeDevideInfo) {
        //        NSLog(@"设备界面更新设备信息>>>>>");
        [self.tableView reloadData];
    }
    if (type == KKBLEAcceptTypeDevideMAC) {
        [self.tableView reloadData];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation

   // In a storyboard-based application, you will often want to do a little preparation before navigation
   - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
   // Get the new view controller using [segue destinationViewController].
   // Pass the selected object to the new view controller.
   }
 */

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView                              = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.backgroundColor              = UIColorHEX(0xf0f2f5);
        _tableView.separatorStyle               = UITableViewCellSeparatorStyleNone;
        _tableView.delegate                     = self;
        _tableView.dataSource                   = self;
        _tableView.sectionHeaderHeight          = 0;
        _tableView.sectionFooterHeight          = 0;
        _tableView.showsVerticalScrollIndicator = YES;
        if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {
            [_tableView setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)];
        }
        if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {
            [_tableView setLayoutMargins:UIEdgeInsetsMake(0, 15, 15, 15)];
        }
        _tableView.separatorColor = UIColorHEXA(0xd2d2d2, 0.5);
        [self.tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];
    }
    return _tableView;
}

#pragma mark - tbvDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return _array1.count;
    }
    else if(section == 1)
    {
        return _array2.count;
    }
    else
    {
        return _array3.count;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 10;
    }
    return 20;
}

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *bgView = [[UIView alloc]initWithFrame:SNFRAME(0, 0, screenWidth, 20)];
    bgView.backgroundColor = UIColorHEX(0xf0f2f5);
    
    if (section !=0) {
        UIView *lineView = [[UIView alloc] initWithFrame:SNFRAME(20, 10, screenWidth-40, 0.5)];
        lineView.backgroundColor = UIColorHEX(0xd5d5d5);
        [bgView addSubview:lineView];
    }
    
    return bgView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString        *identifier = NSStringFromClass([self class]);
    UITableViewCell *cell       = [tableView dequeueReusableCellWithIdentifier:identifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
    }
    cell.height = 50;
    cell.textLabel.font       =  SNFONTREGULAR(17);
    cell.detailTextLabel.font = SNFONTREGULAR(15);
    cell.textLabel.textColor = UIColorHEX(0x161616);
    cell.detailTextLabel.textColor = UIColorHEX(0x96969F);

    cell.accessoryType  = UITableViewCellAccessoryDisclosureIndicator;
    if (indexPath.section == 0) {
        NSString *title = _array1[indexPath.row];
        cell.textLabel.text = title;
        if (indexPath.row == 0) {
            if (SN_PublicClass.isBoind) {
                if (KK_BLEConnect.isConnected) {
                    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ %@", KK_BLEModel.bleName, HHH_Text(@"已连接")];
                } else {
                  cell.detailTextLabel.text =  [NSString stringWithFormat:@"%@ %@", KK_BLEModel.bleName, HHH_Text(@"设备未连接")];
                }
            } else {
                cell.detailTextLabel.text = HHH_Text(@"未绑定设备，请先绑定手环");
            }
            if(!KK_BLEConnect.centerPowerOn)
            {
                cell.detailTextLabel.text = HHH_Text(@"蓝牙未打开");
            }
            cell.imageView.image = [UIImage imageNamed:@"手环设备"];
        }
        if (indexPath.row == 1) {
//            cell.accessoryType = UITableViewCellAccessoryNone;
            cell.imageView.image = [UIImage imageNamed:@"电量"];
            if (KK_BLEConnect.isConnected) {
                cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ %ld%%", SN_Text(@"当前电量"), (long)SN_USER.bleBatteryQuantity];
            } else {
                cell.detailTextLabel.text = HHH_Text(@"暂无数据");
            }
        }
    }
    
    if (indexPath.section == 1) {
        NSString *title = _array2[indexPath.row];
        cell.textLabel.text = title;
        NSArray *imageArray = @[@"相机(1)", @"搜索", @"健康", @"日程(1)", @"闹钟(1)"];
        cell.imageView.image = [UIImage imageNamed:imageArray[indexPath.row]];
    }
    
    if (indexPath.section == 2) {
        NSString *title = _array3[indexPath.row];
        cell.textLabel.text = title;
        cell.imageView.image = [UIImage imageNamed:@"推送"];
    }
    
    UIView *tempView1 = [[UIView alloc] initWithFrame:cell.frame];
    tempView1.backgroundColor   = UIColorHEXA(0xd2d2d2, 0.5);
    cell.selectedBackgroundView = tempView1;

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];

    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            FindBlueViewController *vc = [FindBlueViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
    
    if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            CameraViewController *cameraVC = [[CameraViewController alloc]init];
            [self.navigationController pushViewController:cameraVC animated:YES];
        }
        if (indexPath.row == 1) {
            FindBandView *findBandView = [[FindBandView alloc]initWithFrame:CGRectMake(0, 0, HHHWIDTH, HHHHEIGHT)];
            [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:findBandView];
            [findBandView animationUp];
            [KK_BLESend sendSetFindBle:YES withUpdateBlock:^(id object, KKBLEAcceptType type)
             {
             }];
        }

        if (indexPath.row == 2) {
            HealthSetViewController *healthVC = [[HealthSetViewController alloc]init];
            CustomTabBar            *tabBar   = (CustomTabBar *)self.tabBarController;
            [tabBar hiddenTheTabBarView];
            [self.navigationController pushViewController:healthVC animated:YES];
        }
        if (indexPath.row == 3) {
            ScheduleViewController *scheduleVC = [[ScheduleViewController alloc]init];
            CustomTabBar           *tabBar     = (CustomTabBar *)self.tabBarController;
            [tabBar hiddenTheTabBarView];
            [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
            [self.navigationController pushViewController:scheduleVC animated:YES];
        }
        if (indexPath.row == 4) {
            AlarmViewController *alarmVC = [[AlarmViewController alloc]init];
            CustomTabBar        *tabBar  = (CustomTabBar *)self.tabBarController;
            [tabBar hiddenTheTabBarView];
            [self.navigationController pushViewController:alarmVC animated:YES];
        }
    }

    if (indexPath.row == 0 && indexPath.section == 2) {
        if (SN_USER.isNewAncs) {
            MessagePushViewController2 *pushVC = [[MessagePushViewController2 alloc]init];
            CustomTabBar               *tabBar = (CustomTabBar *)self.tabBarController;
            [tabBar hiddenTheTabBarView];
            [self.navigationController pushViewController:pushVC animated:YES];
        } else {
            MessagePushViewController *pushVC = [[MessagePushViewController alloc]init];
            CustomTabBar              *tabBar = (CustomTabBar *)self.tabBarController;
            [tabBar hiddenTheTabBarView];
            [self.navigationController pushViewController:pushVC animated:YES];
        }
    }
}

@end

